package org.delphy.crimson
{
	import mx.containers.Canvas;
	import mx.core.Container;
	
	import flash.display.DisplayObject;
	
	import org.delphy.crimson.crimsonSunkenPanelClasses.*;

	public class CrimsonSunkenPanel extends Canvas
	{
		[Bindable]
		public var title:String;
		
		private var content:Canvas = new Canvas();
		
		private var titleBar:CrimsonSunkenPanelTitleBar;
				
		public function CrimsonSunkenPanel()
		{
			super();
			styleName = "crimsonSunkenPanel";
		}
		
		override protected function createChildren():void{
			super.createChildren();
			
			titleBar = new CrimsonSunkenPanelTitleBar();
			titleBar.title = title;
			
			rawChildren.addChild(titleBar);
			rawChildren.addChild(content);
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			
			titleBar.width = unscaledWidth;	
			
			content.width = unscaledWidth;
			content.height = unscaledHeight - 24;
			content.y = 24;
		}

		override public function addChild(child:DisplayObject):DisplayObject{
			// The first time this function is called, we maybe counter the problem that at this time, content is null.
			// So, we need to check if it is necessery to create a content
				
			return Container(content).addChild(child);
		}
		
		override public function addChildAt(child:DisplayObject, index:int):DisplayObject{
			return Container(content).addChildAt(child,index);
		}
		
		override public function getChildAt(index:int):DisplayObject{
			return Container(content).getChildAt(index);
		}
		
		override public function getChildByName(name:String):DisplayObject{
			return Container(content).getChildByName(name);
		}
		
		override public function getChildIndex(child:DisplayObject):int{
			return Container(content).getChildIndex(child);
		}		
	}
}